﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using QMSDAL;

namespace QuaManSys.CusSatiSur
{
    public partial class CusSatSurReminderBox : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["CurUser"] != null)
            {
                //根据当前用户的身份显示消息提醒栏
                CurUser user = (CurUser)Session["CurUser"];
                //string dept = user.department;
                ShowReminderList(user);
            }
            else
            {
                //跳转到登录页面
                Response.Redirect("~/Login.aspx");
            }
        }
        private void ShowReminderList(CurUser user)
        {
            string emId = user.employeeId;
            ////根据emID查询雇员角色
            //string empRoles = "A";
            string dept = user.department;  //雇员部门

            //查询当前用户对内部信息录入和内部收件箱具有的操作权限
            List<string> listOwnedReg = Permission.QueryOpers(emId, "3A");
            List<string> listOwnedRem = Permission.QueryOpers(emId, "3B");
            List<string> listDeptReg = Permission.QueryOpers(dept, "3A");
            List<string> listDeptRem = Permission.QueryOpers(dept, "3B");
            //需要重新登记的信息
            #region 重新登记的消息

            if (listOwnedReg.Contains("A"))
            {
                List<string> listInfoReg = Permission.QueryCusInfoStatus("登记");
                if (listInfoReg.Count != 0)
                {
                    int i = 1;
                    string proUrl = "InfomationCollection.aspx";
                    pnlReminder1.GroupingText = "以下表需要您完善信息";
                    foreach (var item in listInfoReg)
                    {
                        FillPanelWithControl(pnlReminder1, i++, item, "登记", proUrl);
                    }
                }
                else
                {
                    //todo:如果没有需要重新登记的信息
                }
            }
            #endregion
            //待分发的信息
            #region 待汇总的消息

            if (listOwnedRem.Contains("C0") || listDeptRem.Contains("C0"))
            {
                List<string> listInfoDis = Permission.QueryCusInfoStatus("汇总");
                if (listInfoDis.Count != 0)
                {

                    pnlReminder2.GroupingText = "待汇总列表";
                    int i = 1;
                    string disUrl = "InfomationCollection.aspx";
                    foreach (var item in listInfoDis)
                    {
                        FillPanelWithControl(pnlReminder2, i++, item, "汇总", disUrl);
                    }

                }
            }
            #endregion
            //待处理的消息
            #region 待审核的消息

            if (listOwnedRem.Contains("C1") || listDeptRem.Contains("C1"))
            {
                List<string> listInfoPro = Permission.QueryCusInfoStatus("审核");
                if (listInfoPro.Count != 0)
                {

                    pnlReminder3.GroupingText = "待审核列表";
                    int i = 1;
                    string disUrl = "CusSatiSurAuditing.aspx";
                    foreach (var item in listInfoPro)
                    {
                        FillPanelWithControl(pnlReminder3, i++, item, "审核", disUrl);
                    }

                }
            }
            #endregion

            //待收集的信息
            #region 收集的消息

            if (listOwnedRem.Contains("C2") || listDeptRem.Contains("C2"))
            {
                List<string> listInfoFile = Permission.QueryCusInfoStatus("收集");
                if (listInfoFile.Count != 0)
                {

                    pnlReminder4.GroupingText = "待收集列表";
                    int i = 1;
                    string disUrl = "InfomationCollection.aspx";
                    foreach (var item in listInfoFile)
                    {
                        FillPanelWithControl(pnlReminder4, i++, item, "收集", disUrl);
                    }

                }
            }
            #endregion

            //待归档的信息
            #region 闭环的消息

            if (listOwnedRem.Contains("D0") || listDeptRem.Contains("D0"))
            {
                List<string> listInfoFile = Permission.QueryCusInfoStatus("待闭环");
                if (listInfoFile.Count != 0)
                {

                    pnlReminder5.GroupingText = "待闭环列表";
                    int i = 1;
                    string disUrl = "CusSatiSurCloseCirle.aspx";
                    foreach (var item in listInfoFile)
                    {
                        FillPanelWithControl(pnlReminder5, i++, item, "闭环", disUrl);
                    }

                }
            }
            #endregion
        }

        /// <summary>
        /// 根据数据库里的记录，自动在panel生成仅显示信息编号的列表
        /// </summary>
        /// <param name="panel"></param>
        /// <param name="i"></param>
        /// <param name="infoId"></param>
        private void FillPanelWithControl(Panel panel, int i, string infoId, string needTo, string url)
        {
            Label myLabel = new Label();
            panel.Controls.Add(myLabel);
            myLabel.Text = i.ToString() + " . 质量信息编号为：" +
                infoId + "需要" + needTo + "。";

            HyperLink innerHref = new HyperLink();
            panel.Controls.Add(innerHref);
            innerHref.Text = "立即处理。";
            innerHref.NavigateUrl = url + "?id=" +
                infoId;
            panel.Controls.Add(new LiteralControl("<br />"));
        }
    }
}